//
//  HeaderView.m
//  10_HomeWork
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "HeaderView.h"
#import "Carouse.h"
#import "DMCycleImage.h"

@interface HeaderView ()
@property (nonatomic, strong) UIButton *loan_button;
@property (nonatomic, strong) UIButton *market_button;
@property (nonatomic, strong) UIButton *basePrice_button;
@property (nonatomic, strong) UIButton *secondHand_button;
@property (nonatomic, strong) UILabel *loan_label;
@property (nonatomic, strong) UILabel *market_label;
@property (nonatomic, strong) UILabel *basePrice_label;
@property (nonatomic, strong) UILabel *secondHand_label;
@property (nonatomic, strong) UIScrollView *cycleImageView;
@end

@implementation HeaderView
- (instancetype)initWithFrame:(CGRect)frame array:(NSArray<NSString *> *)array {
    self = [super initWithFrame:frame];
    if (self) {
        [self createViewWithFrame:frame array:array];
    }
    return self;
}
- (void)createViewWithFrame:(CGRect)frame array:(NSArray *)array{
    // 创建轮播图
    DMCycleImage *dmCycle = [[DMCycleImage alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height * 2 / 3)];
    [dmCycle setImagesWithArray:array];
    [self addSubview:dmCycle];
//    Carouse *cycle = [[Carouse alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height * 2 / 3) array:array];
//    [self addSubview:cycle];
//    cycle.scrollView.backgroundColor = [UIColor cyanColor];
    // 创建四个button
    self.loan_button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.market_button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.basePrice_button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.secondHand_button = [UIButton buttonWithType:UIButtonTypeCustom];
    CGFloat buttonTopOfScrollView = 10;
    CGFloat buttonY = frame.size.height * 2 / 3 + buttonTopOfScrollView;
    CGFloat buttonWidth = 50;
    CGFloat buttonHegiht = 50;
    CGFloat leftMargin = 20;
    CGFloat rightMargin = 20;
    CGFloat buttonSpaceing = (frame.size.width - 4 * buttonWidth - leftMargin - rightMargin) / 3;
    _loan_button.frame = CGRectMake(leftMargin, buttonY, buttonWidth, buttonHegiht);
    _market_button.frame = CGRectMake(leftMargin + buttonWidth + buttonSpaceing, buttonY, buttonWidth, buttonHegiht);
    _basePrice_button.frame = CGRectMake(leftMargin + buttonWidth * 2 + buttonSpaceing * 2, buttonY, buttonWidth, buttonHegiht);
    _secondHand_button.frame = CGRectMake(leftMargin + buttonWidth * 3 + buttonSpaceing * 3, buttonY, buttonWidth, buttonHegiht);
    [_loan_button setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    [_market_button setImage:[UIImage imageNamed:@"2"] forState:UIControlStateNormal];
    [_basePrice_button setImage:[UIImage imageNamed:@"3"] forState:UIControlStateNormal];
    [_secondHand_button setImage:[UIImage imageNamed:@"4"] forState:UIControlStateNormal];
    // 创建四个label
    CGFloat labelWidth = 75;
    CGFloat labelHeight = 20;
    CGFloat labelSpacing = buttonSpaceing - 25;
    CGFloat labelY = buttonY + buttonHegiht + 5;
    
    self.loan_label = [[UILabel alloc] initWithFrame:CGRectMake(leftMargin - 13, labelY, labelWidth, labelHeight)];
    self.market_label = [[UILabel alloc] initWithFrame:CGRectMake(leftMargin - 13 + labelWidth + labelSpacing, labelY, labelWidth, labelHeight)];
    self.basePrice_label = [[UILabel alloc] initWithFrame:CGRectMake(leftMargin - 10 + labelWidth * 2 + labelSpacing * 2, labelY, labelWidth, labelHeight)];
    self.secondHand_label = [[UILabel alloc] initWithFrame:CGRectMake(leftMargin - 14 + labelWidth * 3 + labelSpacing * 3, labelY, labelWidth, labelHeight)];
    _loan_label.text = @"贷款买车";
    _market_label.text = @"直销车型";
    _basePrice_label.text = @"底价买车";
    _secondHand_label.text = @"二手车";
    _loan_label.textAlignment = NSTextAlignmentCenter;
    _market_label.textAlignment = NSTextAlignmentCenter;
    _basePrice_label.textAlignment = NSTextAlignmentCenter;
    _secondHand_label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_loan_button];
    [self addSubview:_market_button];
    [self addSubview:_basePrice_button];
    [self addSubview:_secondHand_button];
    [self addSubview:_loan_label];
    [self addSubview:_market_label];
    [self addSubview:_basePrice_label];
    [self addSubview:_secondHand_label];
}

@end
